<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2017/11/22
  Time: 16:10
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<input>
<head>
    <c:set var="root" value="${pageContext.request.contextPath}"/>
    <meta http-equiv="Content-Language" content="zh-cn">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link href="${root}/bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css" />
    <script src="${root}/bootstrap/js/jquery-2.1.0.js"></script>
    <script src="${root}/bootstrap/js/bootstrap.js"></script>

    <style type="text/css">
        #biaoti{
            height: 20%;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }
        #hidden{
            text-decoration: none;
        }
    </style>
    <title>产品列表</title>
</head>
<div style="background-color: #f5fafe;width: 100%;height: 100%" >
    <div class="row">
        <c:forEach var="c" items="${page.pageList}" varStatus="status">
            <div class="col-xs-2">
                <div class="thumbnail">
                    <img src="${root}/${c.image}" alt="" style= "height: 20%">
                    <div class="caption">
                        <h5 id="biaoti">${c.pname}</h5>
                        <p>市场价：${c["market_price"] eq 1}</p>

                        <p>是否热销：
                            <c:if test="${c[\"is_hot\"] eq 1}">是</c:if>
                            <c:if test="${c[\"is_hot\"] ne 1}">否</c:if>
                        </p>
                        <p><a href="${pageContext.request.contextPath}/AdminProductEditUI?pid=${c.pid}" class="btn btn-primary btn-sm" role="button">修改</a> <a href="${pageContext.request.contextPath}/AdminProductDelete?pid=${c.pid}" class="btn btn-default btn-sm" role="button">删除</a></p>
                    </div>
                </div>
            </div>
        </c:forEach>
    </div>

    <hr>

    <c:if test="${pageBean.currenPage>1}">
        <a href="${pageContext.request.contextPath}/pageServlet?currentPage=${pageBean.currentPage-1}">上一页</a>
    </c:if>

    <c:choose>
        <%--当总页数小于等于10的时候，显示全部--%>
        <c:when test="${pageBean.pageCount<=10}">
            <c:set var="begin" value="1"/>
            <c:set var="end" value="${pageBean.pageCount}"/>
        </c:when>
        <%--当总页数大于10的时候，只显示10页--%>
        <c:otherwise>
            <%--显示策略--%>
            <c:set var="begin" value="${pageBean.currentPage -5}"/>
            <c:set var="end" value="${pageBean.currentPage +4}"/>

            <c:if test="${begin<1}">
                <c:set var="begin" value="1"/>
                <c:set var="end" value="10" />
            </c:if>
            <c:if test="${end > page.pageCount}">
                <c:set var="begin" value="${pageBean.pageCount-9}"/>
                <c:set var="end" value="${pageBean.pageCount}"/>
            </c:if>
        </c:otherwise>
    </c:choose>

    <nav aria-label="...">
        <ul class="pagination">
            <c:if test="${page.page ne 1}">
                <li><a href="${root}/AdminProductFindALL?${page.page-1}" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a></li>
            </c:if>

            <c:forEach var="num" begin="${begin}" end="${end}">
                <c:choose>
                    <c:when test="${page.page eq num}">
                        <li class="active"><span>${num}<span class="sr-only"></span></span></li>
                    </c:when>
                    <c:otherwise>
                        <li><a href="${root}/AdminProductFindALL?page=${num}">${num}<span class="sr-only">${num}</span></a></li>
                    </c:otherwise>
                </c:choose>
            </c:forEach>
            <c:if test="${page.page ne page.pageCount}">
                <li><a href="${root}/AdminProductFindALL?page=${page.page+1}" aria-label="Previous"><span aria-hidden="true">&raquo;</span></a></li>
            </c:if>
        </ul>
    </nav>



</div>
</body>
</html>
